package edu.towson.greenteam.table;
import edu.towson.greenteam.Iterator;


public class TableNotOccupiedItr implements Iterator<Table> 
{
	
	protected Tables data;
	protected int index = 0;
	
	public TableNotOccupiedItr(final Tables tables) {
		setData(tables);
	}
	

	public void setData(final Tables tables) {
	    this.data = tables;
	    index = 0;
	}

	@Override
	public boolean hasNext() {
		return (index <= data.size()-1);
	}

	@Override
	public Table next() {
		while (hasNext()) {
			if (data.get(index).isOccupied() == false){
				Table returnTable =  data.get(index);
				index++;
				return returnTable;
			}
			else {
				index++;
			}
		}
		return null;
		//throw new IndexOutOfBoundsException("only " + data.size() + " elements");
	}

	public boolean hasPrevious() {
		return index > 0;
		
	}
	
	public void reset() {
		index = 0;
	}


	@Override
	public Table previous() {
		if (hasPrevious() == false) {
			return null;
		} else {
			return data.get(--index);
        }
	}

}
